package com.beiye.drivertransport.fragment;


import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.beiye.drivertransport.BuildConfig;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.PromotionCodeActivity;
import com.beiye.drivertransport.bean.CheckBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.MineUseBean;
import com.beiye.drivertransport.bean.SigninDataBean;
import com.beiye.drivertransport.bean.UpPhotoBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.CameraCanUseUtils;
import com.beiye.drivertransport.utils.FileUtil;
import com.beiye.drivertransport.utils.ImageUtil;
import com.beiye.drivertransport.utils.LogUtils;
import com.beiye.drivertransport.utils.MessageEventPhoto;
import com.beiye.drivertransport.utils.TakePhotoDialog;
import com.beiye.drivertransport.utils.ToastUtil;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.squareup.picasso.Picasso;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


/**
 * Created by Lc on 2017/11/23.
 */
//我的界面
public class MineFgt extends TwoBaseFgt {


    RelativeLayout fe_mine;//处理代码监听乱跳转首页的子界面

    RelativeLayout re_personal_information;

    RelativeLayout re_setting;//设置界面

    RelativeLayout re_curriculum_vitae;//履历界面

    TextView tv_username;//用户姓名

    TextView tv_mine4;//用户当前积分

    ImageView fgt_circleview;//照片

    ImageView img_mine;//积分

    LinearLayout le_mine1;//签到得分

    LinearLayout le_mine2;//淘宝商城

    RelativeLayout re_integral_record;//积分记录

    RelativeLayout re_pay;//付款记录

    RelativeLayout fg_mine_rl_member;//付款记录

    //请求访问外部存储
    private static final int READ_EXTERNAL_STORAGE_REQUEST_CODE = 103;
    //请求写入外部存储
    private static final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 104;

    RelativeLayout rvPromotionCode;
    private File tempFile;
    private int type;
    //请求相机
    private static final int REQUEST_CAPTURE = 100;
    //请求相册
    private static final int REQUEST_PICK = 101;
    //请求截图
    private static final int REQUEST_CROP_PHOTO = 102;


    private PopupWindow mSigninEveryDayPopWindow;
    private PopupWindow mSigninNoEveryDayPopWindow;
    private int uoSn;

    @Override
    public int getLayoutId() {
        return R.layout.main_mine_fgt;

    }

    @Override
    public void onClick(View view) {

    }


    /*
     *每日签到方法
     */
    private void showSigninEveryDayPopwindow() {

        //设置contentView
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.popwindowsignin_layout, null);
        mSigninEveryDayPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        mSigninEveryDayPopWindow.setFocusable(false);
        mSigninEveryDayPopWindow.setOutsideTouchable(false);
        mSigninEveryDayPopWindow.showAtLocation(le_mine1, Gravity.CENTER, 0, 0);
        TextView tv_signinsure = (TextView) contentView.findViewById(R.id.tv_signin1);
        final TextView tv_sign = (TextView) contentView.findViewById(R.id.tv_signin);//积分数
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "user/userPoint/signInForT/" + userId);
        x.http().get(params, new org.xutils.common.Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                SigninDataBean signBean = JSON.parseObject(result, SigninDataBean.class);
                int pointNo = signBean.getData().getPointNo();//获得积分
                int curPointNo = signBean.getData().getCurPointNo();//当前用户积分
                tv_sign.setText("恭喜您获得" + pointNo + "积分!");
                tv_mine4.setText(curPointNo + "");
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                showToast("网络连接错误");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
//        OkGo.get(AppInterfaceConfig.BASE_URL + "user/userPoint/signInForT/" + userId)
//                .tag(this)
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(String s, Call call, Response response) {
//                        SigninDataBean signBean = JSON.parseObject(s, SigninDataBean.class);
//                        int pointNo = signBean.getData().getPointNo();//获得积分
//                        int curPointNo = signBean.getData().getCurPointNo();//当前用户积分
//                        tv_sign.setText("恭喜您获得"+pointNo+"积分!");
//                        tv_mine4.setText(curPointNo+"");
//                    }
//
//                    @Override
//                    public void onError(Call call, Response response, Exception e) {
//                        super.onError(call, response, e);
//
//                    }
//                });
        tv_signinsure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mSigninEveryDayPopWindow.dismiss();
                img_mine.setImageResource(R.mipmap.normal_btm);

            }
        });
    }

    /*
     *已签到方法
     */
    private void showSigninnoEveryDayPopwindow() {

        //设置contentView
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.popwindowsigninno_layout, null);
        mSigninNoEveryDayPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        mSigninNoEveryDayPopWindow.setFocusable(true);
        mSigninNoEveryDayPopWindow.setOutsideTouchable(true);
        mSigninNoEveryDayPopWindow.showAtLocation(le_mine1, Gravity.CENTER, 0, 0);
        TextView tv_signinsure = (TextView) contentView.findViewById(R.id.tv_signin2);
        tv_signinsure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mSigninNoEveryDayPopWindow.dismiss();
            }
        });
    }

    @Override
    public void initData() {
        fe_mine = (RelativeLayout)getActivity().findViewById(R.id.fe_mine);
        re_personal_information = (RelativeLayout) getActivity().findViewById(R.id.re_personal_information);
        re_setting = (RelativeLayout)getActivity().findViewById(R.id.re_setting);
        re_curriculum_vitae = (RelativeLayout)getActivity().findViewById(R.id.re_curriculum_vitae);
        tv_username = (TextView)getActivity().findViewById(R.id.tv_mine3);
        tv_mine4 = (TextView)getActivity().findViewById(R.id.tv_mine4);
        fgt_circleview = (ImageView)getActivity().findViewById(R.id.fgt_circleview);
        img_mine = (ImageView)getActivity().findViewById(R.id.img_mine);
        le_mine1 = (LinearLayout)getActivity().findViewById(R.id.le_mine1);
        le_mine2 = (LinearLayout)getActivity().findViewById(R.id.le_mine2);
        re_integral_record = (RelativeLayout)getActivity().findViewById(R.id.re_integral_record);
        re_pay = (RelativeLayout)getActivity().findViewById(R.id.re_pay);
        fg_mine_rl_member = (RelativeLayout)getActivity().findViewById(R.id.fg_mine_rl_member);
        rvPromotionCode = (RelativeLayout) getActivity().findViewById(R.id.rv_promotionCode);

        SharedPreferences sharedPreferences = getContext().getSharedPreferences("StaticData", Context.MODE_PRIVATE);
        String adId = sharedPreferences.getString("adId", "");
        uoSn = sharedPreferences.getInt("uoSn", 0);
        if(adId.length()>2){
            if (adId.substring(0, 2).equals("32")) {
                rvPromotionCode.setVisibility(View.VISIBLE);
            }else{
                rvPromotionCode.setVisibility(View.GONE);
            }
        }

        //注册EventBus
        EventBus.getDefault().register(this);
        fe_mine.setOnClickListener(null);
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!hidden){
            SharedPreferences sharedPreferences = getContext().getSharedPreferences("StaticData", Context.MODE_PRIVATE);
            String adId = sharedPreferences.getString("adId", "");
            uoSn = sharedPreferences.getInt("uoSn", 0);
            if(adId.length()>2){
                if (adId.substring(0, 2).equals("32")) {
                    rvPromotionCode.setVisibility(View.VISIBLE);
                }else{
                    rvPromotionCode.setVisibility(View.GONE);
                }
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);//反注册EventBus
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(MessageEventPhoto event) {
        String message = event.getPhotourl();
        LogUtils.e("测试", "onEventMainThread: " + message);
        SharedPreferences sp = getActivity().getSharedPreferences("photoUrl13", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("photoUrl", message);
        editor.commit();
        Picasso.with(getActivity()).load(Uri.parse(message)).placeholder(R.mipmap.my_head).into(fgt_circleview);//加载图片
    }

    private void showTakePhotoPopupWindow() {
        TakePhotoDialog.Builder builder = new TakePhotoDialog.Builder(getActivity());
        builder.setTitle("为方便后台管理员审核您的安全学习");
        builder.setMessage("请上传您的个人照片");
        builder.setPositiveButton("从手机中选择照片", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //权限判断
                if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
                        != PackageManager.PERMISSION_GRANTED) {
                    //申请READ_EXTERNAL_STORAGE权限
                    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                            READ_EXTERNAL_STORAGE_REQUEST_CODE);
                } else {
                    //跳转到相册
                    gotoPhoto();
                }

                dialog.dismiss();

                //设置你的操作事项
            }
        });
        builder.setPositiveButton1("拍摄照片", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //权限判断
                if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
                        != PackageManager.PERMISSION_GRANTED) {
                    //申请WRITE_EXTERNAL_STORAGE权限
                    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
                } else {
                    //跳转到调用系统相机

                    if (!CameraCanUseUtils.isCameraCanUse()) {
                        ToastUtil.showShortToast(getActivity(), "请到手机设置界面里找驾运宝允许开启照相");
                        return;
                    }
                    gotoCamera();
                }
                dialog.dismiss();

                //设置你的操作事项
            }
        });
        builder.setNegativeButton("跳过", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                //设置你的操作事项
            }
        });
        builder.create().show();


    }

    /**
     * 跳转到相册
     */
    private void gotoPhoto() {
        Log.d("evan", "*****************打开图库********************");
        //跳转到调用系统图库
        Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(Intent.createChooser(intent, "请选择图片"), REQUEST_PICK);
    }

    /**
     * 跳转到照相机
     */
    private void gotoCamera() {
        Log.d("evan", "*****************打开相机********************");
        //创建拍照存储的图片文件
        tempFile = new File(FileUtil.checkDirPath(Environment.getExternalStorageDirectory().getPath() + "/image/"), System.currentTimeMillis() + ".jpg");

        //跳转到调用系统相机
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            //设置7.0中共享文件，分享路径定义在xml/file_paths.xml
            intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + ".fileProvider", tempFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
        } else {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
        }
        startActivityForResult(intent, REQUEST_CAPTURE);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        switch (requestCode) {
            case REQUEST_CAPTURE: //调用系统相机返回
                if (resultCode == Activity.RESULT_OK) {
                    Uri uri = Uri.fromFile(tempFile);
                    String cropImagePath = FileUtil.getRealFilePathFromUri(getContext(), uri);
                    Bitmap bitMap = BitmapFactory.decodeFile(cropImagePath);
                    fgt_circleview.setImageBitmap(bitMap);
                    File file = new File(cropImagePath);
                    LoginUserBean userInfo = UserManger.getUserInfo();
                    LoginUserBean.DataBean data = userInfo.getData();
                    String userId = data.getUserId();
                    try {
                        FileInputStream fis = new FileInputStream(file);
                        Bitmap bitmapByUrl = BitmapFactory.decodeStream(fis);
                        bitmapByUrl = ImageUtil.compressScale(bitmapByUrl);
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
                        bitmapByUrl.compress(Bitmap.CompressFormat.JPEG, 100, bos);
                        bos.flush();
                        bos.close();
                        uploadImg(file, userId);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {

                    }
                    //uploadFile(getContext(),file,4);
                    //     gotoClipActivity(Uri.fromFile(tempFile));
                }
                break;
            case REQUEST_PICK:  //调用系统相册返回
                if (resultCode == Activity.RESULT_OK) {
                    Uri uri = intent.getData();
                    String cropImagePath = FileUtil.getRealFilePathFromUri(getContext(), uri);
                    Bitmap bitMap = BitmapFactory.decodeFile(cropImagePath);
                    fgt_circleview.setImageBitmap(bitMap);
                    File file = new File(cropImagePath);
                    LoginUserBean userInfo = UserManger.getUserInfo();
                    LoginUserBean.DataBean data = userInfo.getData();
                    String userId = data.getUserId();
                    try {
                        FileInputStream fis = new FileInputStream(file);
                        Bitmap bitmapByUrl = BitmapFactory.decodeStream(fis);
                        bitmapByUrl = ImageUtil.compressScale(bitmapByUrl);
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
                        bitmapByUrl.compress(Bitmap.CompressFormat.JPEG, 100, bos);
                        bos.flush();
                        bos.close();
                        uploadImg(file, userId);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {

                    }
                    //uploadFile(getContext(),file,4);
                    //    gotoClipActivity(uri);
                }
                break;
//            case REQUEST_CROP_PHOTO:  //剪切图片返回
//                if (resultCode == Activity.RESULT_OK) {
//                    final Uri uri = intent.getData();
//                    if (uri == null) {
//                        return;
//                    }
//                    String cropImagePath = FileUtil.getRealFilePathFromUri(getActivity(), uri);
//                    Bitmap bitMap = BitmapFactory.decodeFile(cropImagePath);
//                    fgt_circleview.setImageBitmap(bitMap);
//                    File file=new File(cropImagePath);
//                    LoginUserBean userInfo = UserManger.getUserInfo();
//                    LoginUserBean.DataBean data = userInfo.getData();
//                    String userId = data.getUserId();
//                    uploadImg(file,userId);
//
//                }
//                break;
        }
    }

    private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
    private final OkHttpClient client = new OkHttpClient();

    private void uploadImg(File mediaFile, String userId) {
        // mImgUrls为存放图片的url集合
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);

        if (mediaFile != null) {
            builder.addFormDataPart("headPhoto", mediaFile.getName(), RequestBody.create(MEDIA_TYPE_PNG, mediaFile));
            builder.addFormDataPart("userId", userId);
        }
        MultipartBody requestBody = builder.build();
        //构建请求
        Request request = new Request.Builder()
                .url(AppInterfaceConfig.BASE_URL + "wx/uploadOfHeadPhoto")//地址
                .post(requestBody)//添加请求体
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                LogUtils.e("上传失败", e.getLocalizedMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                LogUtils.e("上传成功", str);
                UpPhotoBean upPhotoBean = JSON.parseObject(str, UpPhotoBean.class);
                String data = upPhotoBean.getData();
                SharedPreferences sp = getActivity().getSharedPreferences("photoUrl13", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putString("photoUrl", data);
                editor.commit();
                LogUtils.e("上传图片", data);

            }
        });

    }

    /**
     * 外部存储权限申请返回
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == WRITE_EXTERNAL_STORAGE_REQUEST_CODE) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
                gotoCamera();
            }
        } else if (requestCode == READ_EXTERNAL_STORAGE_REQUEST_CODE) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
                gotoPhoto();
            }
        }
    }

    /**
     * 打开截图界面
     */
//    public void gotoClipActivity(Uri uri) {
//        if (uri == null) {
//            return;
//        }
//        Intent intent = new Intent();
//        intent.setClass(getActivity(), ClipImageActivity.class);
//        intent.putExtra("type", type);
//        intent.setData(uri);
//        startActivityForResult(intent, REQUEST_CROP_PHOTO);
//    }
    @Override
    public void onResume() {
        super.onResume();
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        new Login().getUser(userId, this, 2);
        SignInData();
        ModyPhotoUrl();//查询移动端是否可以上传头像
    }

    /*
     *签到积分显示
     */
    private void SignInData() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "user/userPoint/judeSignIn/" + userId);
        x.http().get(params, new org.xutils.common.Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                CheckBean signBean = JSON.parseObject(result, CheckBean.class);
                Integer signBeanData = signBean.getData();
                if (signBeanData != null) {
                    if (signBeanData == 1)//当日已签到
                    {
                        img_mine.setImageResource(R.mipmap.normal_btm);
                    } else if (signBeanData == 0) {//当日未签到
                        img_mine.setImageResource(R.mipmap.day_singin_btm);
                    }
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                showToast("网络连接错误");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });

    }

    @Override
    public void requestData() {

        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        new Login().getUser(userId, this, 1);
        SignInData();
        ModyPhotoUrl();//查询移动端是否可以上传头像
    }

    private void ModyPhotoUrl() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userId = data.getUserId();
        RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "sys/orgExtraFunction/findMobileFuMark/" + userId);
        x.http().get(params, new org.xutils.common.Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
                Integer checkBeanData = checkBean.getData();
                SharedPreferences sp = getActivity().getSharedPreferences("MineFgt", Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putInt("checkphoto", checkBeanData);
                edit.commit();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                showToast("网络连接错误");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });


    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 1) {
            MineUseBean mineUseBean = JSON.parseObject(result, MineUseBean.class);
            MineUseBean.DataBean data = mineUseBean.getData();
            String userName = data.getUserName();
            if (userName == null) {
                tv_username.setText("");

            } else {
                tv_username.setText(userName);
            }

            String photoUrl = data.getPhotoUrl();
            SharedPreferences sp = getActivity().getSharedPreferences("photoUrl13", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sp.edit();
            editor.putString("photoUrl", photoUrl);
            editor.commit();
            if (photoUrl == null) {
                fgt_circleview.setImageResource(R.mipmap.my_head);
            } else {

                Picasso.with(getActivity()).load(Uri.parse(photoUrl)).placeholder(R.mipmap.my_head).into(fgt_circleview);//加载图片
            }
            int userPoint = data.getUserPoint();
            if (userPoint == 0) {
                tv_mine4.setText(0 + "");
            } else {
                tv_mine4.setText(userPoint + "");
            }

        } else if (what == 2) {
            MineUseBean mineUseBean = JSON.parseObject(result, MineUseBean.class);
            MineUseBean.DataBean data = mineUseBean.getData();
            String userName = data.getUserName();
            if (userName == null) {
                tv_username.setText("");

            } else {
                tv_username.setText(userName);
            }

//            String photoUrl = data.getPhotoUrl();
//            SharedPreferences sp = getActivity().getSharedPreferences("photoUrl13", Context.MODE_PRIVATE);
//            SharedPreferences.Editor editor = sp.edit();
//            editor.putString("photoUrl", photoUrl);
//            editor.commit();
//            if (photoUrl == null) {
//                fgt_circleview.setImageResource(R.mipmap.my_head);
//            } else {
//
//                Picasso.with(getActivity()).load(Uri.parse(photoUrl)).placeholder(R.mipmap.my_head).into(fgt_circleview);//加载图片
//            }
            int userPoint = data.getUserPoint();
            if (userPoint == 0) {
                tv_mine4.setText(0 + "");
            } else {
                tv_mine4.setText(userPoint + "");
            }
        }


        super.onSuccess(result, call, response, what);
    }

    @Override
    public void onUserVisible() {

    }


    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return false;
    }




    /*public void uploadFile(Context context, File faceImgFile, int type) {
        HelpUtil.uploadFile(context, faceImgFile, type, new OSSUpFileListener() {
            @Override
            public void onSuccess(WriterBean bean) {
                String ossUrl = bean.getData().getObjectAcsUrl();
                SharedPreferences sp = getActivity().getSharedPreferences("photoUrl13", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putString("photoUrl", ossUrl);
                editor.commit();
            }

            @Override
            public void onFail(String msg, WriterBean bean) {

            }
        });
    }*/
}
